<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
    <link rel="stylesheet" type="text/css" href="static/css/style.css" />
    <script type="text/javascript" src="static/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="static/js/share.js"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?ak=htWvwYPknA71cGYsWv6QnlzQ&type=lite&v=1.0"></script>
    <title>商品详情</title>
</head>
<body>
<div class="warp">
    <div class="install_tip_top">
        <div class="logo_ico"></div>
        <div class="logo"></div>
        <div class="info">中国首个工匠综合服务平台</div>
        <a class="intsll_btn" href="javascript:void(0)" onclick="share.download('http://image.qjbuluo.com/o_1da695eu21jg0j3310pbd5rtcua.apk', '')">免费安装</a>
    </div>
    <div class="pro_info">
        <div class="loading"></div>
    </div>
    <div class="zw60"></div>
    <div class="botton_menubox1">
        <ul>
            <li class="share"></li>
            <li class="fav"></li>
        </ul>
        <a href="javascript:void(0)" class="chat">在线咨询</a>
        <a href="javascript:void(0)" class="tel"></a>
    </div>
</div>
<script type="text/javascript">
    var id = share.get_param('id');
    if(!id) {
        alert('系统错误');
    }
    function init_info(data) {
        var html = '';
        var init_comments = function(data) {
            var html = '<ul class="comment_list">';
            if(data.comments.length > 0) {
                $.each(data.comments,function(index,value){
                    var commentContent = '';
                    switch(value.category) {
                        case 0:
                            commentContent = '<span class="username3">'+value.userName+'</span>取消了点赞.';
                            break;
                        case 1:
                            commentContent = '<span class="username3">'+value.userName+'</span>赞了这条动态';
                            break;
                        case 2:
                            commentContent = '<div class="hbinfo">'+value.userName+'给'+value.targetName+'打赏了一个红包.</div>';
                            break;
                        case 3:
                            commentContent = '<span class="username3">'+value.userName+'</span>分享了此动态.';
                            break;
                        case 4:
                            commentContent = value.content;
                            break;
                    }
                    html+='\
                    <li>\
                        <a href="userprofile.html?id='+ value.userId +'" class="avatar" style="background-image:url('+value.userHead+')"></a>\
                        <div class="comment_text">\
                            <div class="username">'+ value.userName +'</div>\
                            <div class="sty2">\
                                '+commentContent+'\
                                <p class="note1">'+value.createTime +'</p>\
                            </div>\
                            <div class="red_bag2 '+(value.awarded ? 'active' : '')+'"><span class="nums">'+(value.award > 0 ? value.award : '')+'</span></div>\
                            <div class="approve2 '+(value.agreed ? 'active' : '')+'"><span class="nums">'+(value.agree > 0 ? value.agree : '')+'</span></div>\
                        </div>\
                    </li>\
                ';
                })
            } else {
                html += '\
                <div class="no_log_tip">万水千山总是情，给个评论行不行</div>\
            ';
            }
            html = html + '</ul>';
            return html;
        }
        var init_content = function(list) {
            var html = '';
            $.each(list,function(index,value){
                switch(parseInt(value.type)) {
                    case 0:
                        html += '<p>'+value.content+'</p>';
                        break;
                    case 1:
                        html += '<p><img src="'+value.content+'" /></p>';
                        break;
                    case 2:
                        html += '\
                        <p>\
                            <video onended="complete_play(this)" preload="auto" playsinline="true" x5-video-player-type="h5" controls >\
                                <source src ="'+value.content+'" type="video/mp4">\
                             Your browser does not support the video tag.\
                            </video>\
                        </p>\
                    ';
                        break;
                    case 3:
                        html += '<p><audio src="'+value.content+'" controls ></audio></p>';
                        break;
                }
            })
            return html;
        };
        var init_goodsType = function(data) {
            var html = '';
            if(typeof(data.goodsType) != 'undefined') {
                var typestr = '';
                switch(parseInt(data.goodsType)) {
                    case 0:
                        typestr += '新品';
                        break;
                    case 1:
                        typestr += '二手';
                        break;
                }
                if(typestr) {
                    html += '\
                    <div class="bqbox">\
                        <span class="es">'+typestr+'</span>\
                    </div>\
                '
                }
            }
            return html;
        };
        var init_price = function(data) {
            var html = '';
            if(parseInt(data.type) == 0 || parseInt(data.type) == 1) {
                if(parseInt(data.price) == 0 || typeof(data.unit) == 'undefined') {
                    html += '<div class="rmbbox"><strong>面议</strong></div>';
                } else {
                    html += '<div class="rmbbox"><strong>'+data.price+'</strong>/'+data.unit+'</div>';
                }

            }
            return html;
        }
        html += '\
        <div class="userCardArea"><div class"loading"></div></div>\
        <div class="shop_detail_t">\
            <div class="timebox">发布时间：'+data.createTime+'</div>\
            '+init_goodsType(data)+'\
            <h2>'+data.summary+'</h2>\
            '+init_price(data)+'\
        </div>\
        <div class="shop_detail_content">\
            '+init_content(data.entries)+'\
        </div>\
        <div class="shop_detail_end"><div><span>完</span></div></div>\
        <div class="shop_detail_address">\
            <div class="topbox">\
                <div class="avatar" style="background-image:url('+data.userHead+')"></div>\
                <div class="infobox">\
                    <h4 class="companyname">\
                        <span '+(data.authed ? 'class="rz"' : '')+'>'+data.userName+'</span>\
                    </h4>\
                    <div class="companynamepj">\
                        口碑'+data.score+'      查看其它<span class="font1">'+(data.goodsCount - 1)+'</span>个商品\
                    </div>\
                    <div class="dz">\
                        '+data.location+'<br>\
                        '+(typeof(data.dist) != 'undefined' ? '<p class="font2">距离 '+data.dist+'km</p>' : '')+'\
                        <a href="#" class="tel"></a>\
                    </div>\
                </div>\
            </div>\
            <div class="mapbox" id="map_container"></div>\
        </div>\
        <div class="shop_detail_pl">\
            <div class="title">\
                <h4>评论 <span>'+(parseInt(data.comment) > 0 ? '('+data.comment+')' : '')+'</span></h4>\
                <a href="javascript:void(0)" class="showMore">查看更多</a>\
            </div>\
            <div class="comment_box">\
                <a href="javascript:void(0)" class="avatar"></a>\
                <input placeholder="快来写下你的评论吧~" type="text" disabled />\
            </div>\
            '+init_comments(data)+'\
        </div>\
    ';
        $('.pro_info').append(html);
        share.creat_map('map_container', data.longitude, data.latitude);
        load_userDec(data.userId);
        zg_bind();
    }

    function init_userinfo(data) {
        var html = '';
        html += '\
        <div class="resume_card">\
            <div class="card_box">\
                <div class="avatar" style="background-image:url('+ data.headUrl +')"></div>\
                <div class="username">\
                    <div>\
                        '+ data.nickname +'<i class="sfrz '+(data.authed ? '' : 'hide')+'"></i>\
                    </div>\
                </div>\
                <ul class="info2">\
                    <li>\
                        <div>\
                            <strong>'+share.fomat_num(data.extend.fanses).num+'</strong>\
                            <b>'+share.fomat_num(data.extend.fanses).unit+'</b>\
                        </div>\
                        <p>粉丝</p>\
                    </li>\
                    <li>\
                        <div>\
                            <strong>'+share.fomat_num(data.extend.follows).num+'</strong>\
                            <b>'+share.fomat_num(data.extend.follows).unit+'</b>\
                        </div>\
                        <p>关注</p>\
                    </li>\
                    <li>\
                        <div>\
                            <strong>'+share.fomat_num(data.extend.agrees).num+'</strong>\
                            <b>'+share.fomat_num(data.extend.agrees).unit+'</b>\
                        </div>\
                        <p>获赞</p>\
                    </li>\
                    <li>\
                        <div>\
                            <strong>'+share.fomat_num(data.extend.gifts).num+'</strong>\
                            <b>'+share.fomat_num(data.extend.gifts).unit+'</b>\
                        </div>\
                        <p>红包</p>\
                    </li>\
                    <li>\
                        <div>\
                            <strong>'+share.fomat_num(data.extend.rewards).num+'</strong>\
                            <b>'+share.fomat_num(data.extend.rewards).unit+'</b>\
                        </div>\
                        <p>打赏</p>\
                    </li>\
                </ul>\
            </div>\
        </div>\
    ';
        $('.userCardArea').append(html)
        $('.resume_card .info3 li').on('click',function(){
            alert('下载APP使用此功能.')
        })
    }

    function load_userDec(id) {
        $('.userCardArea .loading').show();
        var obj = {
            url: share.get_api_url()+'user/detail/' + id,
            success: function(data) {
                if(parseInt(data.status) != 0) {
                    share.add_tip_a($('.userCardArea'), data.msg);
                } else if (parseInt(data.status) == 0) {
                    share.remove_tip();
                    init_userinfo(data.result)
                }

            },
            complete : function() {
                $('.userCardArea .loading').hide();
            }
        }
        share.ajax_control(obj);
    }

    function zg_bind() {
        $('.pro_info .companyname').on('click', function(){
            alert('下载APP查看更多商品.')
        })
        $('.pro_info .companynamepj').on('click', function(){
            alert('下载APP查看更多商品.')
        })
        $('.pro_info .tel').on('click', function(){
            alert('下载APP使用此功能.')
        })
        $('.shop_detail_pl .showMore').on('click', function(){
            alert('下载APP查看更多评论信息.')
        })
        $('.shop_detail_pl .comment_box').on('click', function(){
            alert('下载APP参与评论.')
        })
        $('.zginfobox .red_bag2').on('click', function(){
            alert('下载APP使用此功能.')
        })
        $('.zginfobox .approve2').on('click', function(){
            alert('下载APP使用此功能.')
        })
        $('.botton_menubox1').on('click', function(){
            alert('下载APP使用此功能.')
        })
    }
    function get_info(id) {
        $('.pro_info .loading').show();
        var obj = {
            url: share.get_api_url()+'goods/detail/' + id,
            success: function(data) {
                if(parseInt(data.status) != 0) {
                    share.add_tip_a($('.pro_info'), data.msg);
                } else if (parseInt(data.status) == 0) {
                    share.remove_tip();
                    init_info(data.result);
                }

            },
            complete : function() {
                $('.pro_info .loading').hide();
            }
        }
        share.ajax_control(obj);
    }
    $(function(){
        get_info(id);
    })
</script>
</body>
</html>
